﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Syncer
{
    public static class Log
    {
        private static StreamWriter sw = null;

        public static void OpenLog()
        {
            try
            {
                if (!File.Exists("Log.txt")) File.Create("Log.txt");
                sw = File.AppendText("Log.txt");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }


        public static void CloseLog()
        {
            if (sw != null) sw.Close();
        }

        private static bool fileExist = false;

        public static void Exception(string exception,Exception ex)
        {
            Log2("Exception", exception + "\n" + ex.ToString());

        }

        public static void Info(string info)
        {
            Log2("Info", info);
        }

        public static void Debug(string debug)
        {
            Log2("Debug", debug);
        }

        private static void Log2(string Type, string content)
        {
            string loginfo = "[" + DateTime.Now.ToShortTimeString() + "][" + Type + "] : " + content;
            Console.WriteLine(loginfo);
            sw.Write(loginfo + Environment.NewLine);
        }

    }
}
